package com.doctor.ui.medicalknowledge;

import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;

import com.doctor.bean.ArticleBean;
import com.doctor.bean.ArticleListBean;
import com.doctor.comm.ConstConfig;
import com.doctor.comm.DialogHelper;
import com.doctor.comm.LoadingTip;
import com.doctor.database.DbOperator;
import com.doctor.ui.BaseFragmentActivity;
import com.doctor.ui.R;
import com.doctor.ui.consulting.view.ConsultingActivity;
import com.doctor.ui.homedoctor.HomeDoctorActivity;
import com.doctor.ui.office.OfficeActivity;

public class KnowledgeActivity extends BaseFragmentActivity{

	/**
	 * 医学知识医疗技术
	 */
	
	private KnowledgeFirstFrag knowledgeFirstFrag;
	
	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
        setContentView(R.layout.base_activity);
		
		initiaView();
		initiaSubMenu();
		getData();
		
		//通知用户升级新数据
		noticeNewData();
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		//改变主菜单背景颜色
		officeBtn.setBackgroundResource(R.color.light_green);
		knowledgeBtn.setBackgroundResource(R.color.green);
		consultingBtn.setBackgroundResource(R.color.light_green);
		homeDocBtn.setBackgroundResource(R.color.light_green);
	}
	
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		//改变主菜单背景颜色
		knowledgeBtn.setBackgroundResource(R.color.light_green);
	}
	
	@Override
	protected void initiaView() {
		// TODO Auto-generated method stub
		super.initiaView();
		knowledgeFirstFrag=null;
		knowledgeFirstFrag=new KnowledgeFirstFrag();
		FragmentTransaction transaction=getSupportFragmentManager().beginTransaction();
		transaction.replace(R.id.frag_container, knowledgeFirstFrag).commit();
		
	}
	
	
	
	@Override
	protected void onHeaderClicked() {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	protected void onOfficeClicked() {
		// TODO Auto-generated method stub
		final Intent intent=new Intent(KnowledgeActivity.this,OfficeActivity.class);
		startActivity(intent);
		finish();
	}
	
	@Override
	protected void onConsultingClicked() {
		// TODO Auto-generated method stub
		final Intent intent=new Intent(KnowledgeActivity.this,ConsultingActivity.class);
		startActivity(intent);
		finish();
	}
	
	@Override
	protected void onHomeDoctorClicked() {
		// TODO Auto-generated method stub
		final Intent intent=new Intent(KnowledgeActivity.this,HomeDoctorActivity.class);
		startActivity(intent);
		finish();
	}
	
	@Override
	protected void searchByKeyWord(final String keyWord) {
		// TODO Auto-generated method stub
		LoadingTip.showDialog(KnowledgeActivity.this, "正在搜索，请稍等......");
		
		new Thread() {
			public void run() {
				final List<ArticleBean> beanList = DbOperator.getInstance(KnowledgeActivity.this).searchArticles(keyWord, KnowledgeActivity.this);
				runOnUiThread(new Runnable() {
					public void run() {
						LoadingTip.hideDialog();
						if (beanList == null || beanList.size() <= 0) {
					        DialogHelper.showConfirmDialog(KnowledgeActivity.this, "没有相关搜索结果，请更换搜索关键词再试试！");
					        return;
				        }
						ArticleListBean list=new ArticleListBean(beanList);
						Intent searchIntent=new Intent(KnowledgeActivity.this, KnowledgeSearchActivity.class);
						searchIntent.putExtra(ConstConfig.BEAN, list);
						startActivity(searchIntent);
					}
				});
			}
		}.start();
	}
	
	
	
}
